
function getNetifIpInfoData() {
  var body = {"request": "get_netif_ip","netif":"ETH_WAN"};
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        // // hideLoading("msg-load");
        if(c.status_code == 0){
          document.getElementById("eth-ip-mode").value = c.mode;
          document.getElementById("static-ip").value = c.static_ip;
          document.getElementById("static-netmask").value = c.static_netmask;
          document.getElementById("static-gw").value = c.static_gw;
        }
      } catch (d) {
          alert("错误："+c.message)
      }
  })
}

function postNetifIpInfoData() {
  var mode = document.getElementById("eth-ip-mode").value;
  var ip = document.getElementById("static-ip").value;
  var netmask = document.getElementById("static-netmask").value;
  var gw = document.getElementById("static-gw").value;
  var body = {
                  "request": "set_netif_ip",
                  "netif":"ETH_WAN",
                  "static_ip": ip,
                  "static_netmask": netmask,
                  "static_gw": gw,
                  "mode": parseInt(mode)
              };
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        if(c.status_code == 0){
          alert("设置成功")
        } else {
          alert("错误："+c.message)
        }
      } catch (d) {
        alert("错误："+c.message)
      }
  })
}

function getNetifStaIpInfoData() {
  var body = {"request": "get_netif_ip","netif":"WIFI_STA_DEF"};
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        // // hideLoading("msg-load");
        if(c.status_code == 0){
          document.getElementById("sta-ip-mode").value = c.mode;
          document.getElementById("sta-static-ip").value = c.static_ip;
          document.getElementById("sta-static-netmask").value = c.static_netmask;
          document.getElementById("sta-static-gw").value = c.static_gw;
        }
      } catch (d) {
          alert("错误："+c.message)
      }
  })
}

function postNetifStaIpInfoData() {
  var mode = document.getElementById("sta-ip-mode").value;
  var ip = document.getElementById("sta-static-ip").value;
  var netmask = document.getElementById("sta-static-netmask").value;
  var gw = document.getElementById("sta-static-gw").value;
  var body = {
                  "request": "set_netif_ip",
                  "netif":"WIFI_STA_DEF",
                  "static_ip": ip,
                  "static_netmask": netmask,
                  "static_gw": gw,
                  "mode": parseInt(mode)
              };
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        if(c.status_code == 0){
          alert("设置成功")
        } else {
          alert("错误："+c.message)
        }
      } catch (d) {
        alert("错误："+c.message)
      }
  })
}

function getNetifApIpInfoData() {
  var body = {"request": "get_netif_ip","netif":"WIFI_AP_DEF"};
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        // // hideLoading("msg-load");
        if(c.status_code == 0){
          document.getElementById("ap-ip-mode").value = c.mode;
          document.getElementById("ap-static-ip").value = c.static_ip;
          document.getElementById("ap-static-netmask").value = c.static_netmask;
          document.getElementById("ap-static-gw").value = c.static_gw;
        }
      } catch (d) {
          alert("错误："+c.message)
      }
  })
}

function postNetifApIpInfoData() {
  var mode = document.getElementById("ap-ip-mode").value;
  var ip = document.getElementById("ap-static-ip").value;
  var netmask = document.getElementById("ap-static-netmask").value;
  var gw = document.getElementById("ap-static-gw").value;
  var body = {
                  "request": "set_netif_ip",
                  "netif":"WIFI_AP_DEF",
                  "static_ip": ip,
                  "static_netmask": netmask,
                  "static_gw": gw,
                  "mode": parseInt(mode)
              };
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        if(c.status_code == 0){
          alert("设置成功")
        } else {
          alert("错误："+c.message)
        }
      } catch (d) {
        alert("错误："+c.message)
      }
  })
}

function setDefaultNetif() {
  const netif = document.getElementById('default-netif-select').value;
  var body = {"request": "set_mesh_config","default_netif":netif};
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        if(c.status_code == 0){
          alert("设置成功")
        } else {
          alert("错误："+c.message)
        }
      } catch (d) {
        alert("错误："+d.message)
      }
  })
}

function getDefNetif() {
  var body = {"request": "get_mesh_config"};
  Ajax.postDeviceRequest(COM_CONSTANT.POST_DEVICE_REQUEST_URL, JSON.stringify(body), function(c) {
      c = JSON.parse(c);
      // console.log(c);
      try {
        if(c.status_code == 0){
          document.getElementById('default-netif-select').value = c.default_netif;
        } else {
          alert("错误："+c.message)
        }
      } catch (d) {
        alert("错误："+d.message)
      }
  })
}

function initHash () {
  console.log('页面第一次加载')

  const leftMenuElement = document.getElementById('idLeftMenuNetwork');
  leftMenuElement.classList.add('content');

  selectTitle(document.getElementsByClassName('header-title-one')[0])
  selectContent('netifSelectedShow')

  getDefNetif()
  getNetifIpInfoData()
  getNetifStaIpInfoData()
  getNetifApIpInfoData()
}
